// ignore_for_file: no_leading_underscores_for_local_identifiers

import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';

class DateUtil {
  //转换为中文月份
  static String convertNumberToChinese(dynamic number, [bool isWeek = true]) {
    String stringBuffer = "";

    switch (number) {
      case 1:
        stringBuffer = "一";
        break;
      case 2:
        stringBuffer = "二";
        break;
      case 3:
        stringBuffer = "三";
        break;
      case 4:
        stringBuffer = "四";
        break;

      case 5:
        stringBuffer = "五";
        break;
      case 6:
        stringBuffer = "六";
        break;
      case 7:
        if (isWeek) {
          stringBuffer = "日";
        } else {
          stringBuffer = "七";
        }
        break;
      case 8:
        stringBuffer = "八";
        break;
      case 9:
        stringBuffer = "九";
        break;
      case 10:
        stringBuffer = "十";
        break;
      case 11:
        stringBuffer = "十一";
        break;
      case 12:
        stringBuffer = "十二";
        break;

      default:
    }
    return stringBuffer;
  }

  //获取当前今天
  static int getCurrentDay() {
    return DateTime.now().day;
  }

  //得到这个月的第一天是星期几
  static int getPlaceholderDays({required int year, required int month}) {
    var days = DateTime(year, month).weekday % 7;
    return days;
  }

  // 获取当前月份天数
  static int getCurrentMonthDays({required int year, required int month}) {
    if (month == 2) {
      //判断2月份是闰年月还是平年
      if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
        return 29;
      } else {
        return 28;
      }
    } else if (month == 1 ||
        month == 3 ||
        month == 5 ||
        month == 7 ||
        month == 8 ||
        month == 10 ||
        month == 12) {
      return 31;
    } else {
      return 30;
    }
  }

  // 获取当前月在日历上的行数
  static int getRowsForMonthYear({required int year, required int month}) {
    //当前月天数
    final int _currentDays = getCurrentMonthDays(year: year, month: month);
    var _placeholderDays = getPlaceholderDays(year: year, month: month);
    int rows = (_currentDays + _placeholderDays) ~/ 7;
    int remainder = (_currentDays + _placeholderDays) % 7;
    if (remainder > 0) rows = rows + 1;
    return rows;
  }


 

  /// 根据year年的第week周，查询本周的开始和截止日期
  static Map<String, dynamic> weekToDayFormat(int year, int week) {
 
    String startDateString = "";

    String endDateString = "";

    return {
      "startDate": startDateString,
      "endDate": endDateString,
    };
  }

  static int getWeek(String date) {
    final dateTime = DateTime.parse(date);
    debugPrint('星期：${dateTime.weekday}');
    return dateTime.weekday;
  }

  ///默认加载毫秒
  static const Duration fast = Duration(milliseconds: 300);
  static const Duration med = Duration(milliseconds: 600);
  static const Duration slow = Duration(milliseconds: 900);
  static const Duration pageTransition = Duration(milliseconds: 200);

  //获取初始化动画时间
  static Duration getdelay(int index) {
    final delay = 100.ms + (100 * index).ms;
    return delay;
  }
}
